import { currentUserID } from "@/utils/common.js";
import { utils } from 'hi-ui';
//采购结算数据集配置
export default {
    id: "SettlementDetailEntity",
    modelFile: "purchase/settlement/dataset/SettlementDetailEntity.xml",
    //主从配置
    relation: {
        selfField: ["FNUMBER"],
        parentField: ["FNUMBER"]
    },
    sortFields: [
        "FID",
        "FNUMBER",
        "FISNUMBER",
        "FORDERMONEY",
        "FFREEMONEY",
        "FAMOUNT",
        "FCOUNT",
        "FAMOUNTPAYABLE",
        "FPAYABLE",
        "FCREATEDATE",
        "FUSERID",
        "FENTERPRISEDESC",
        "FENTERPRISEID",
        "FSORT",
    ],
    element: {
        eleSort: {
            field: "FSORT",
        }
    },
    fields: {
        FID: {
            name: "FID", //字段ID
            label: "ID", //字段描述
            dbtype: "dbString", //数据类型
            default: {
                //默认值
                //rule: 'first', //prior   填充规则
                exps: (data) => {
                    //填充表达式
                    return utils.string.guid();
                },
            },
        },
        FNUMBER: {
            name: "FNUMBER", //字段ID
            label: "单号", //字段描述
            dbtype: "dbString", //数据类型
            required: true,
            readonly: true,
            length: 25,

        },
        FUSERID: {
            name: "FUSERID", //字段ID
            label: "创建人", //字段描述
            dbtype: "dbString", //数据类型
            required: true,
            readonly: true,
            length: 25,
            default: {
                //默认值
                exps: (data) => {
                    //填充表达式
                    return currentUserID();
                },
            },
        },
        FCREATEDATE: {
            name: "FCREATEDATE", //字段ID
            label: "创建时间", //字段描述
            dbtype: "dbDate", //数据类型
            required: true,
            readonly: true,
            default: {
                //默认值
                exps: (data) => {
                    //填充表达式
                    return utils.date.format(new Date(), "yyyy-MM-dd HH:mm:ss");
                },
            },
        },
        FSORT: {
            name: "FSORT", //字段ID
            label: "排序", //字段描述
            dbtype: "dbInt", //数据类型

        },
        FISNUMBER: {
            name: "FISNUMBER", //字段ID
            label: "验收入库单", //字段描述
            dbtype: "dbString", //数据类型
            required: true,
            readonly: true,
            length: 25,
        },

        FORDERMONEY: {
            name: "FORDERMONEY", //字段ID
            label: "单据金额", //字段描述
            dbtype: "dbFloat", //数据类型
            required: true,
            readonly: true,
        },

        FCOUNT: {
            name: "FCOUNT", //字段ID
            label: "类目数", //字段描述
            dbtype: "dbInt", //数据类型
            required: true,
            readonly: true,


        },
        FAMOUNT: {
            name: "FAMOUNT", //字段ID
            label: "件数", //字段描述
            dbtype: "dbFloat", //数据类型
            required: true,
            readonly: true,


        },

        FAMOUNTPAYABLE: {
            name: "FAMOUNTPAYABLE", //字段ID
            label: "未付金额", //字段描述
            dbtype: "dbFloat", //数据类型
            readonly: true,
            required: true,
            /*   default: {
                  //默认值
                  exps: (data) => {
                      //填充表达式
                      return data.FORDERMONEY
                  },
              }, */
        },

        FPAYABLE: {
            name: "FPAYABLE", //字段ID
            label: "付款金额", //字段描述
            dbtype: "dbFloat", //数据类型
            required: true,
        },
        FSUPPLIER: {
            name: "FSUPPLIER", //字段ID
            label: "供应商", //字段描述
            dbtype: "dbString", //数据类型


        },
        FSUPPLIERID: {
            name: "FSUPPLIERID", //字段ID
            label: "供应商ID", //字段描述
            dbtype: "dbString", //数据类型

        }, FENTERPRISEDESC: {
            name: "FENTERPRISEDESC", //字段ID
            label: "企业名称", //字段描述
            dbtype: "dbString", //数据类型
            length: 25,
        },
        FENTERPRISEID: {
            name: "FENTERPRISEID", //字段ID
            label: "企业ID", //字段描述
            dbtype: "dbString", //数据类型
            length: 25,
        },

    },
    validateList: [{
        "expr": function (store) {
            var data = store.data;
            for (var i = 0; i < data.length; i++) {
                var item = data[i];
                if (item.FPAYABLE * 1 <= 0) {
                    return new Error('付款金额不能为零')
                }
                var FPAYABLE = item.FPAYABLE, FAMOUNTPAYABLE = item.FAMOUNTPAYABLE || 0;
                if (FPAYABLE > FAMOUNTPAYABLE) {
                    return new Error(item.FISNUMBER + "付款金额不能大于未付金额");
                }

            }

        }
    }]

}